<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>

<div class="pageContent" style="overflow:auto">

    <form class="layui-form" id="addForm" enctype="multipart/form-data">
        <br>
        <input type="hidden" name="id" value="${ap.id}">
        <input type="hidden" name="type" value="${ap.type}">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">标题：</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="typeName" value="${ap.typeName}" readonly disabled="">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">上次修改人：</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="updateUser" name="updateUser" value="${ap.updateUser}"
                           readonly disabled="">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">上次修改时间：</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="updateTime" value="${ap.updateTime}" readonly
                           disabled="">
                </div>
            </div>

        </div>
        <!-- 富文本编辑器 -->
        <div class="pageFormContent" layoutH="52">
            <textarea id="lay_edit" name="content" lay-verify="content">${ap.content}</textarea>
        </div>
        <br>
        <div class="layui-form-item">
            <input class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="formUpdate"
                   type="button" id="updata" value="保存修改">
            <input class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="returnMsg"
                   type="button" id="return" value="取消">
        </div>
    </form>

</div>

<script>
    layui.use(['layer', 'form', 'element', 'layedit'], function () {

        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form;

        var mylayedit = layui.layedit;

        //向编辑器插入图片
        mylayedit.set({
            uploadImage: {
                url: 'GYWM/uploadImage.do?typeName='+"${ap.typeName}" //接口url
                , type: 'post' //默认post
            }
        });
        //注意：layedit.set 一定要放在 build 前面，否则配置全局接口将无效。

        //建立编辑器
        var index = mylayedit.build('lay_edit', {
            height: 500 //设置编辑器高度
        });

        //提交时把值同步到文本域中
        form.verify({
            //content富文本域中的lay-verify值
            content: function (value) {
                // 将富文本编辑器的值同步到之前的textarea中
                return mylayedit.sync(index);
            }
        });

        $("#return").click(function () {
            // console.log("点击了一下")
            queryDetails(${ap.id});
        });

        //监听提交
        form.on('submit(formUpdate)', function (data) {
            /*console.log("点击了一下");
            console.log(data.field);*/
            $.ajax({
                url: "GYWM/toSave.do",
                type: "post",
                data: data.field,
                dataType: 'json',
                success: function (json) {
                    /*console.log("第二次值返回成功！")
                    console.log(json)*/
                    if (json.statusCode == 200) {
                        layer.msg(json.message, {icon: 6, time: 2000});
                    } else {
                        layer.msg(json.message, {icon: 5, time: 2000});

                    }
                    queryDetails(${ap.id});
                }
            })
            return false;
        });
    });


</script>